use async_trait::async_trait;
use clap::Parser;

use crate::commands::commands::Command;
use crate::models::models;
use crate::models::models::command::CommandState;
use crate::utils::command;

#[derive(Debug, Default, Clone, Parser)]
#[clap(disable_help_flag = true)]
struct Args {
    value: String,
}

#[derive(Debug, Default, Clone)]
pub(crate) struct QrCodeCommand {}

#[async_trait]
impl Command for QrCodeCommand {
    async fn execute(&self, command: models::command::Command) -> models::command::Command {
        let args = command::parse_command_args::<Args>(command.args.as_str());
        if args.is_err() {
            return self.save_command_output(command, CommandState::Success, args.unwrap_err().to_string());
        }

        let args = args.unwrap();

        self.save_command_output(command, CommandState::Success, args.value)
    }
}